﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class DayNightController : MonoBehaviour {

    [SerializeField]
	public float EdgeLightMax;

	[SerializeField]
	[Range(-1, 1)]
	public float IsShadow;
 	
	[SerializeField]
	public Color DirectColor;

    [SerializeField]
	public Color IndirectColor;

	[SerializeField]
	public Color SkyTint;

    [SerializeField]
    public Transform LightCenter;
	// Update is called once per frame
	void LateUpdate () {
		Shader.SetGlobalFloat("_EdgeLightMax", EdgeLightMax);
		Shader.SetGlobalFloat("_IsShadow", IsShadow);
		Shader.SetGlobalVector("_DirectColor", DirectColor);
		Shader.SetGlobalVector("_IndirectColor", IndirectColor);
		Shader.SetGlobalVector("_SkyTint2", SkyTint);
        var pos = LightCenter.transform.position;
        var sunScreenPos = Camera.main.WorldToScreenPoint(pos);
        Shader.SetGlobalVector("_SunScreenPos", new Vector4(sunScreenPos.x / Camera.main.pixelWidth, sunScreenPos.y / Camera.main.pixelHeight, 0, 0));

    }
}
